package middleware

import (
	"context"

	"device-admin/internal/app/grpc/service/pubsub"

	"192.168.1.75/go-pkg/logx"
	"google.golang.org/grpc"
)

// var locker sync.RWMutex

// RobotUnaryServerInterceptor robot 拦截器
func RobotUnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
	pubsub.SubHandleInit()
	m, err := handler(ctx, req)
	if err != nil {
		logx.Error(context.Background(), "RobotUnaryServerInterceptor error", logx.Err(err))
	}
	return m, err
}

// RobotSteamServerInterceptor robot stream拦截器
func RobotSteamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
	pubsub.SubHandleInit()
	err = handler(srv, ss)
	if err != nil {
		logx.Error(context.Background(), "RobotSteamServerInterceptor error", logx.Err(err))
	}
	return err
}
